<?php

/**
 * @author      Nguyen Duc Thuan <me@ndthuan.com>
 * @copyright   Copyright (c) 2009 Nguyen Duc Thuan <me@ndthuan.com>
 */
class Fete_View_Helper_HeadMeta extends Fete_View_Helper
{
    protected $_output  = '';
    protected $_metaTag = 'META';
    protected $_closeStyle = '';

    public function &headMeta()
    {
        return $this;
    }

    public function &appendName($keyType, $value)
    {
        $this->_output .= '<' . $this->_metaTag 
        . ' name="' . $keyType . '" content="' . $value . '"'
        . $this->_closeStyle . '>';

        return $this;
    }

    public function &prependName($keyType, $value)
    {
        $this->_output = '<' . $this->_metaTag 
        . ' name="' . $keyType . '" content="' . $value . '"'
        . $this->_closeStyle . '>' . $this->_output;

        return $this;
    }

    public function &appendHttpEquiv($keyType, $value)
    {
        $this->_output .= '<' . $this->_metaTag 
        . ' http-equiv="' . $keyType . '" content="' . $value . '"'
        . $this->_closeStyle . '>';

        return $this;
    }

    public function &prependHttpEquiv($keyType, $value)
    {
        $this->_output = '<' . $this->_metaTag 
        . ' http-equiv="' . $keyType . '" content="' . $value . '"'
        . $this->_closeStyle . '>' . $this->_output;

        return $this;
    }

    public function __construct()
    {
        if ('XHTML' === substr($this->docType()->getDocType(), 0, 5)) {
            $this->_metaTag = 'meta';
            $this->_closeStyle = ' /';
        }
    }

    public function __toString()
    {
        return $this->_output;
    }
}